<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .active {
            color: red;
        }
    </style>
</head>
<body>

<div id="app">
    <h2 :class="active">{{msg}}</h2>
    <h2 :class="active">{{msg}}</h2>

    <!-- v-bind传递对象 -->
    <h2 v-bind:class="{类名1: true, 类名2: false}">{{msg}}</h2>

    <!-- 原生class和v-bind的class对象在显示时会自动合并 -->
    <h2 class="title" v-bind:class="{active: isActive, line: isLine}"> {{msg}}</h2>

    <!-- 通过方法获取class数据 -->
    <h2 class="title" v-bind:class="getClasses()"> {{msg}}</h2>
    <!-- 通过按钮控制类对象是否显示 -->
    <button v-on:click="btnClick"> 按钮</button>
</div>
<script src="../js/vue.js"></script>
<script>

    const app = new Vue({
        el: "#app",
        data: {
            msg: "hello",
            isActive: true,
            isLine: true
        },
        methods: {
            btnClick: function () {
                this.isActive = !this.isActive
            },
            getClasses: function () {
                return {active: this.isActive, line: this.isLine}
            }
        }
    })
</script>

</body>
</html>